1 /*
2 Copyright: Marcelo S. N. Mancini (Hipreme|MrcSnm), 2018 - 2021
3 License:   [https://creativecommons.org/licenses/by/4.0/|CC BY-4.0 License].
4 Authors: Marcelo S. N. Mancini
5 
6 	Copyright Marcelo S. N. Mancini 2018 - 2021.
7 Distributed under the CC BY-4.0 License.
8    (See accompanying file LICENSE.txt or copy at
9 	https://creativecommons.org/licenses/by/4.0/
10 */
11 
12 module hip.api.data.image;
13 
14 public interface IImageBase
15 {
16     uint getWidth() const;
17     uint getHeight() const;
18     const(ubyte[]) getPixels() const;
19     ubyte getBytesPerPixel() const;
20     final ushort getBitsPerPixel() const {return getBytesPerPixel()*8;}
21     final size_t getSizeBytes() const{return getBytesPerPixel * getPixels.length;}
22     const(ubyte[]) getPalette() const;
23     final bool hasPalette() const {return getPalette.length != 0;}
24 }
25 
26 public interface IHipImageDecoder : IImageBase
27 {
28     ///Use that for decoding from memory, returns whether data was invalid.
29     bool startDecoding(ubyte[] data, void delegate() onSuccess, void delegate() onFailure);
30     
31     static const(ubyte[4]) getPixel(){return cast(ubyte[4])[255,255,255,255];}
32     ///Dispose the pixels
33     void dispose();
34 }
35 
36 //In progress?
37 public interface IHipPNGDecoder  : IHipImageDecoder{}
38 public interface IHipJPEGDecoder : IHipImageDecoder{}
39 public interface IHipWebPDecoder : IHipImageDecoder{}
40 public interface IHipBMPDecoder  : IHipImageDecoder{}
41 public interface IHipAnyImageDecoder : IHipPNGDecoder, IHipJPEGDecoder, IHipWebPDecoder, IHipBMPDecoder{}
42 
43 
44 public interface IImage : IImageBase
45 {
46     string getName() const;
47     ///loadRaw assumes that you already have the raw pixels to be put on CPU, so, there's no error checking.
48     void loadRaw(in ubyte[] pixels, int width, int height, ubyte bytesPerPixel);
49     /**
50     *   loadMemory expects data to be decoded. This process is not
51     *   instant on Web. A decision was made of putting successful and
52     *   unsuccessful callbacks for that reason. Prefer using the onError callback
53     *   rather than the bool return.
54     */
55     bool loadFromMemory(ubyte[] data, void delegate(IImage self) onSuccess, void delegate() onFailure);
56     bool hasLoadedData() const;
57     ubyte[] convertPalettizedToRGBA() const;
58     ubyte[] monochromeToRGBA() const;
59 }